package test

import ninenineqs._

/**
  * Created by wyc on 6/11/2017.
  * Flatten a nested list structure.
  * Example:
  * scala> flatten(List(List(1, 1), 2, List(3, List(5, 8))))
  * res0: List[Any] = List(1, 1, 2, 3, 5, 8)
  */

class test_p07 extends UnitSpec{
  feature(this.getClass.toString) {
    val L1 = List(List(1, 1), 2, List(3, List(5, 8)))
    val L2 = List[Any]()
    val L3 = List(4)
    val L4 = List(List(3, 4))

    val Ts:List[(List[Any]) => List[Any]]=List(
      p07.flatten_v1,
      p07.flatten_v2
    )

    var v = 1
    for ( func <- Ts ) {
      scenario("flatten_v" + v) {
        assert(func(L1) == List(1, 1, 2, 3, 5, 8))
        assert(func(L2) == List[Any]())
        assert(func(L3) == List(4))
        assert(func(L4) == List(3,4))
      }
      v += 1
    }
  }
}
